package cn.faifai.common.utils;

import org.springframework.context.ConfigurableApplicationContext;

public class SpringContextUtil {
    private static ConfigurableApplicationContext context;
    public static ConfigurableApplicationContext getContext() {
        if (context == null) {
            throw new RuntimeException("ApplicationContext is null");
        }
        return context;
    }
    public static void setContext(ConfigurableApplicationContext context) {
        SpringContextUtil.context = context;
    }

    public static <T> T getBean(Class<T> clazz) {
        return getContext().getBean(clazz);
    }
}
